class Solution(object):
    def gameOfLife(self, board):
        """
        :type board: List[List[int]]
        :rtype: None Do not return anything, modify board in-place instead.
        """
        m = len(board)
        n = len(board[0])

        def judge(i, j):
            count = 0
            for ux, uy in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1), (i - 1, j - 1), (i - 1, j + 1),
                           (i + 1, j - 1), (i + 1, j + 1)]:
                if 0 <= ux < m and 0 <= uy < n:
                    if board[ux][uy] == 1 or board[ux][uy] == 3:
                        count += 1
            if board[i][j] == 0:
                if count == 3:
                    board[i][j] = 2
            else:
                if count < 2 or count > 3:
                    board[i][j] = 3

        for i in range(m):
            for j in range(n):
                judge(i, j)

        for i in range(m):
            for j in range(n):
                if board[i][j] == 2:
                    board[i][j] = 1
                if board[i][j] == 3:
                    board[i][j] = 0

        return board


data = Solution()
board = [[0, 1, 0], [0, 0, 1], [1, 1, 1], [0, 0, 0]]
print(data.gameOfLife(board))
